/**
 * Javascript file for sources needed at userinfo.php
 */

function galaxytool_status_formatter(val, rowIdx, cell) {
	var style = store1.getValues(grid1.getItem(rowIdx),"status_style");
	var url = store1.getValues(grid1.getItem(rowIdx),"url");
	cell.customClasses.push(style);
	cell.customClasses.push("centered_text");
	
	if (url != "") {
		val = "<a class=\""+style+"\" href=\""+url+"\">"+val+"</a>";
		return val;
	} 
	return val;
}
function galaxytool_centered_formatter(val, rowIdx, cell) {
	cell.customClasses.push("centered_text");
	return val;
}
function galaxytool_ingame_formatter(val, rowIdx, cell) {
	var pid = store1.getValues(grid1.getItem(rowIdx),"pid");
	cell.customClasses.push("centered_text");
	
	if (pid != "") {
		val = "<a href=\"playerinformation.php?id="+pid+"\">"+val+"</a>";
		return val;
	} 
	return val;
}
function galaxytool_ally_formatter(val, rowIdx, cell) {
	var aid = store1.getValues(grid1.getItem(rowIdx),"aid");
	cell.customClasses.push("centered_text");
	
	if (aid != "") {
		val = "<a href=\"allyinformation.php?id="+aid+"\">"+val+"</a>";
		return val;
	} 
	return val;
}

function galaxytool_load_new_User(newValue) {
	var store_url = "ajax/ajax_userinfo_ipdetails.php?userid="+newValue;
	
	// reload content from URL
	store4.url = store_url;
	store4.close();
	grid4.setStore(store4);
}

function galaxytool_new_tab_loaded(data) {
	dojo.connect(dijit.byId("user_select"), "onChange", galaxytool_load_new_User );
}

function galaxytool_userinfo_init() {
	// select user defined tab
	var choosen_tab = window.location.hash;
	if (choosen_tab != "") {
		try {
			choosen_tab = choosen_tab.replace(/#select_/, "");
			dijit.byId("tabcontainer").selectChild(dijit.byId(choosen_tab));
		} catch (ignore) {
			// select default tab in case of wrong user input
		}
	}

	dojo.subscribe("tabcontainer-selectChild", function(child) {
		window.location.hash = "#select_" + child.get("id");
		// disable message area
		dojo.byId("messageArea").style.display  = "none";
	});
	
	// dojo.connect(dijit.byId("user_select"), "onChange", galaxytool_load_new_IP ); <-- connection is created on TAB load
	dojo.connect(dijit.byId("tab4"), "onLoad", galaxytool_new_tab_loaded );
}

dojo.ready(galaxytool_userinfo_init);